window: Don't invalidate cssnode during get_preferred_width()
authorBenjamin Otte <otte@redhat.com>
Sat, 14 Nov 2015 17:28:34 +0000 (18:28 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 14 Nov 2015 17:32:08 +0000 (18:32 +0100)
Getting the shadow width must not call gtk_style_context_set_state()
because that will invalidate the node and cause a style-updated emission
which can cause gtk_widget_queue_resize() calls.

And calling queue_resize() from get_preferred_size() essentially means
the size is permanently invalid because you invalidate it while
querying it.

This causes flickering of windows when going from/to backdrop state. To
avoid this we either need to fix the theme to not have different shadow
sizes in those cases or we need to ensure the window doesn't flicker in
the first place.

gtk/gtkwindow.c

index b52a2fafeba1a28d522f861a5b57a4c235c2f88b..db41f91e271330c05f22a40ccbd94020a1e74f53 100644 (file)
@@ -6717,9 +6717,8 @@ get_shadow_width (GtkWindow *window,
   GtkBorder d = { 0 };
   GtkBorder margin;
   GtkStyleContext *context;
-  GtkStateFlags state, s;
+  GtkStateFlags s;
   GtkCssValue *shadows;
-  gint i;
 
   *shadow_width = border;
 
@@ -6738,44 +6737,30 @@ get_shadow_width (GtkWindow *window,
   if (!_gtk_widget_is_toplevel (GTK_WIDGET (window)))
     return;
 
-  state = _gtk_widget_get_state_flags (GTK_WIDGET (window));
   context = _gtk_widget_get_style_context (GTK_WIDGET (window));
 
   gtk_style_context_save_to_node (context, priv->decoration_node);
+  s = gtk_style_context_get_state (context);
 
-  /* We don't want windows to jump as they go to backdrop,
-   * therefore we use the maximum of the decoration sizes
-   * for focused and unfocused.
-   */
-  for (i = 0; i < 2; i++)
-    {
-      if (i == 0)
-        s = state & ~GTK_STATE_FLAG_BACKDROP;
-      else
-        s = state | GTK_STATE_FLAG_BACKDROP;
-
-      gtk_style_context_set_state (context, s);
-
-      /* Always sum border + padding */
-      gtk_style_context_get_border (context, s, &border);
-      gtk_style_context_get_padding (context, s, &d);
-      sum_borders (&d, &border);
+  /* Always sum border + padding */
+  gtk_style_context_get_border (context, s, &border);
+  gtk_style_context_get_padding (context, s, &d);
+  sum_borders (&d, &border);
 
-      /* Calculate the size of the drop shadows ... */
-      shadows = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW);
-      _gtk_css_shadows_value_get_extents (shadows, &border);
+  /* Calculate the size of the drop shadows ... */
+  shadows = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW);
+  _gtk_css_shadows_value_get_extents (shadows, &border);
 
-      if (priv->type != GTK_WINDOW_POPUP)
-        {
-          /* ... and compare it to the margin size, which we use for resize grips */
-          gtk_style_context_get_margin (context, s, &margin);
-          max_borders (&border, &margin);
-        }
-
-      sum_borders (&d, &border);
-      max_borders (shadow_width, &d);
+  if (priv->type != GTK_WINDOW_POPUP)
+    {
+      /* ... and compare it to the margin size, which we use for resize grips */
+      gtk_style_context_get_margin (context, s, &margin);
+      max_borders (&border, &margin);
     }
 
+  sum_borders (&d, &border);
+  *shadow_width = d;
+
   gtk_style_context_restore (context);
 }